#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QColorDialog>
#include <QFontDialog>
#include <QFileDialog>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QColor mycolor = QColorDialog::getColor(QColor(255, 0, 0), this, "我的颜色对话框");
    if (mycolor.isValid())
    {
        QString cmd = QString("background-color: rgb(%1,%2,%3)").arg(mycolor.red()).arg(mycolor.green()).arg(mycolor.blue());
        ui->pushButton->setStyleSheet(cmd);
    }
    else
    {
        qDebug() << "cancel";
    }
}

void MainWindow::on_pushButton_3_clicked()
{
    bool ok;
    auto myfont = QFontDialog::getFont(&ok, this);
    if (ok)
    {
        QString cmd = QString("font: %1pt \"%2\";").arg(myfont.pointSize()).arg(myfont.family());
        ui->pushButton_3->setStyleSheet(cmd);
    }
}

void MainWindow::on_pushButton_4_clicked()
{
    QString myfile = QFileDialog::getOpenFileName(this, "我的文件对话框", "C:/test", "*.txt *.png");
}
